import common from './common'

const api = {
  getRecord: 'ytgz/kcdj/getRecord',
  getListRecordByType: 'ytgz/kcdj/listRecordByType',
  saveRecord: 'ytgz/kcdj/saveRecord',
  delRecord: '/ytgz/kcdj/deleteRecordByIds',
  countPlotByRecordId: 'ytgz/kcdj/countPlotByRecordId',
  listPlot: 'ytgz/kcdj/listPlot',
  listPlotByPage: 'ytgz/kcdj/listPlotByPage',
  savePlot: 'ytgz/kcdj/savePlot',
  deletePlotByIds: 'ytgz/kcdj/deletePlotByIds',
  listPlotItemByPage: 'ytgz/kcdj/listPlotItemByPage',
  savePlotItem: 'ytgz/kcdj/savePlotItem',
  deletePlotItemByIds: 'ytgz/kcdj/deletePlotItemByIds',
  saveClassify: 'ytgz/kcdj/saveClassify',
  saveClassifyItem: 'ytgz/kcdj/saveClassifyItem',
  listClassifyByPlotId: 'ytgz/kcdj/listClassifyByPlotId',
  listClassifyByRecordId: 'ytgz/kcdj/listClassifyByRecordId',
  listClassifyByType: 'ytgz/kcdj/listClassifyByType',
  uploadPlotFile: 'ytgz/kcdj/uploadPlotFile',
  importPlotItemExcel: 'ytgz/kcdj/importPlotItemExcel',
  importPlotFromGis: 'ytgz/kcdj/importPlotFromGis',
  deletePlotByObjectId: 'ytgz/kcdj/deletePlotByObjectId',
  deleteClassifyById: 'ytgz/kcdj/deleteClassifyById',
  getPlotPicture: 'ytgz/kcdj/getPlotPicture',
  deleteClassifyItemByIds: 'app/common/deleteClassifyItemByIds',
  saveClassifyItem2: 'app/common/saveClassifyItem',
  getClassifyById: 'app/common/getClassifyById'
}

const dataService = {};

(function (service) {
  service.getRecord = (recordId) => {
    return common.get(api.getRecord, { id: recordId })
  }
  /**
   * 获取勘测定界列表
   * @param projectId
   * @param type 勘测定界类型
   * @returns {Promise | Promise<unknown>}
   */
  service.getListRecordByType = (projectId, type) => {
    return common.get(api.getListRecordByType, { projectId, type })
  }
  /**
   * 新建、保存勘测定界记录
   * @param data
   * @returns {Promise | Promise<unknown>}
   */
  service.saveRecord = (data) => {
    return common.post(api.saveRecord, {}, data)
  }
  /**
   * 删除勘测定界
   * @param ids
   * @returns {Promise | Promise<unknown>}
   */
  service.delRecord = ids => {
    return common.post(api.delRecord, { ids })
  }
  service.countPlotByRecordId = (recordId) => {
    return common.get(api.countPlotByRecordId, { recordId })
  }
  service.listPlot = (recordId) => {
    return common.get(api.listPlot, { recordId })
  }
  service.savePlot = (recordId, data) => {
    return common.post(api.savePlot, { recordId }, data)
  }
  service.deletePlotByIds = (ids) => {
    return common.post(api.deletePlotByIds, { ids })
  }
  service.listPlotByPage = (recordId, filter) => {
    return common.post(api.listPlotByPage, { recordId }, filter)
  }
  /**
   * 获取地块界址点
   * @param plotId 地块ID
   * @param filter
   * @returns {Promise | Promise<unknown>}
   */
  service.listPlotItemByPage = (plotId, filter) => {
    return common.post(api.listPlotItemByPage, { plotId }, filter)
  }
  /**
   * 新建、保存地块界址点
   * @param plotId 地块ID
   * @param data
   * @returns {Promise | Promise<unknown>}
   */
  service.savePlotItem = (plotId, data) => {
    return common.post(api.savePlotItem, { plotId }, data)
  }
  /**
   * 删除界址点
   * @param ids
   * @returns {Promise | Promise<unknown>}
   */
  service.deletePlotItemByIds = ids => {
    return common.post(api.deletePlotItemByIds, { ids })
  }
  service.saveClassify = (plotId, data) => {
    return common.post(api.saveClassify, { plotId }, data)
  }
  service.saveClassifyItem = (classifyId, data) => {
    return common.post(api.saveClassifyItem, { classifyId }, data)
  }
  service.listClassifyByPlotId = (plotId, buildItem) => {
    return common.get(api.listClassifyByPlotId, { plotId, buildItem })
  }
  service.listClassifyByRecordId = (recordId, buildItem) => {
    return common.get(api.listClassifyByRecordId, { recordId, buildItem })
  }
  service.listClassifyByType = (projectId, type, buildItem) => {
    return common.get(api.listClassifyByType, { projectId, type, buildItem })
  }
  service.uploadPlotFile = (params, file) => {
    const formData = new FormData()
    formData.set('file', file)
    return common.post(api.uploadPlotFile, params, formData)
  }
  service.importPlotItemExcel = (plotId, file, dicName) => {
    const formData = new FormData()
    formData.set('file', file)
    return common.post(api.importPlotItemExcel, { plotId, dicName }, formData)
  }
  service.importPlotFromGis = (projectId, data) => {
    return common.post(api.importPlotFromGis, { projectId }, data)
  }
  service.deletePlotByObjectId = (projectId, objectIds) => {
    return common.post(api.deletePlotByObjectId, { projectId, objectIds }, null)
  }
  service.deleteClassifyById = (classifyId) => {
    return common.post(api.deleteClassifyById, { classifyId }, null)
  }
  service.getPlotPicture = (params) => {
    return common.get(api.getPlotPicture, params)
  }
  service.deleteClassifyItemByIds = (classifyItemIds) => {
    return common.get(api.deleteClassifyItemByIds, { classifyItemIds })
  }
  service.saveClassifyItem2 = (data) => {
    return common.post(api.saveClassifyItem2, null, data)
  }
  service.getClassifyById = (params) => {
    return common.get(api.getClassifyById, params)
  }
})(dataService)

export default dataService
